//
//  VIZHMStatusRetweetedView.swift
//  VIZ微博
//
//  Created by 位立志 on 16/4/14.
//  Copyright © 2016年 位立志. All rights reserved.
//

import UIKit
import SnapKit


class VIZHMStatusRetweetedView: UIView {

    var viewBottom : Constraint?
    
    //转发微博正文
    //var textLabel:UILabel?
    
    private lazy var textLabel: UILabel = UILabel(text: "zhehaibuaisdfghaogh", textColor: UIColor.blackColor(), fontSize: 14)
    /// 图片
    private lazy var picture : VIZPictureView = VIZPictureView()
    
    //
//    var homeStatue:VIZHomeStatuse?
    var cellViewModel : VIZCellViewModel?{
        didSet{
            textLabel.text = cellViewModel?.homeStatuse?.retweeted_status?.text
            //print(cellViewModel?.homeStatuse?.retweeted_status?.text)
            
            textLabel.textAlignment = .Left
            
            self.viewBottom?.uninstall()
            //微博图片设置数据源
            if let urls = cellViewModel?.homeStatuse?.retweeted_status?.pic_urls where urls.count > 0 {
                //有配图
                self.snp_updateConstraints(closure: { (make) -> Void in
                    
                    self.viewBottom = make.bottom.equalTo(picture.snp_bottom).offset(8).constraint
                    
                })
                picture.imageURLs = urls
                picture.hidden = false
            }else{
                
                self.snp_updateConstraints(closure: { (make) -> Void in
                    self.viewBottom = make.bottom.equalTo(textLabel.snp_bottom).offset(8).constraint
                })
                picture.imageURLs = nil
                picture.hidden = true
                
            }

            
            
            
        }
    }
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(textLabel)
        addSubview(picture)
        textLabel.backgroundColor = UIColor(white: 0.95, alpha: 1)
        setUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setUI(){
        
        textLabel.snp_makeConstraints(closure: { (make) -> Void in
            
            //make.left.top.right.equalTo(self)
            make.left.equalTo(self).offset(8)
            make.right.equalTo(self).offset(-8)
            make.top.equalTo(self)
            
        })
        
        picture.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(textLabel.snp_bottom).offset(8)
            make.left.equalTo(textLabel.snp_left)
            
        }
        
        
        self.snp_makeConstraints { (make) -> Void in
            
            self.viewBottom = make.bottom.equalTo(picture.snp_bottom).offset(8).constraint
        }
        
        
    }
    
    
    
    
}
